<?php
//On vérrouille la caméra correspondante dans la base.
require_once("../../config.php");
require_once("myLib.php");
global $CFG, $COURSE, $USER;

//Paramètres
$Ginstid = optional_param('instid', null, PARAM_INT);
$Gfilename = optional_param('filename', null, PARAM_ALPHANUM);

//Permission
if(isset($Ginstid) && isset($Gfilename) ){
    if(is_allowed('mod/podcast:edit', $COURSE->id, $Ginstid)){
        //Supprimer le fichier temporaire.
        if(!strrchr($CFG->podcast_path2tmpfiles, "/") || !strrchr($CFG->podcast_path2tmpfiles, '\\')){
            $command1 = "ssh -i ".$CFG->podcast_path2rsakey." ".$CFG->podcast_username."@".$CFG->podcast_path2pcp." rm ".$CFG->podcast_path2tmpfiles."/".$Gfilename;
            $response =  exec($command1, $output, $return);
        }else{
            $command1 = "ssh -i ".$CFG->podcast_path2rsakey." ".$CFG->podcast_username."@".$CFG->podcast_path2pcp." rm ".$CFG->podcast_path2tmpfiles.$Gfilename;
            $response =  exec($command1, $output, $return);
        }
       if($return != 0){
            $success = "FAILURE";
            //$reason = "Failed to delete tmp file".$CFG->podcast_path2tmpfiles.$Gfilename;
            $reason = $command1;
       }else{
            $success = "SUCCESS";
            $reason = $CFG->podcast_path2tmpfiles.$Gfilename." deleted.";
       }
    }else{
        $success = "FAILURE";
        $reason = "Permission denied.";
    }
}else{
    $success = "FAILURE";
    $reason = "Permission denied.";
}
header('Content-Type: text/xml; charset=UTF-8');
//On rend compte au client du succès ou de l'échec de l'opération.
$doc = new DOMDocument('1.0', 'utf-8');
$message = $doc->createElement( "message" );
$doc->appendChild( $message );
$xmlRespSucc = $doc->createElement( "success" );
$xmlRespSuccWhy = $doc->createElement( "reason" );
$xmlRespSucc->appendChild( $doc->createTextNode( $success ));
$xmlRespSuccWhy->appendChild( $doc->createTextNode( $reason ));
$message->appendChild( $xmlRespSucc );
$message->appendChild( $xmlRespSuccWhy );
echo $doc->saveXML();
?>
